package com.yc.jpyy.appeal.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.yc.jpyy.appeal.dao.AppealDao;
import com.yc.jpyy.appeal.service.AppealService;
import com.yc.jpyy.base.service.BaseService;

@Service
public class AppealServiceimpl extends BaseService implements AppealService {
	
	@Autowired
	private AppealDao appealDao;

	@Override
	public Map<String, Object> addAppeal(Map<String, Object> paramsMap)
			throws DataAccessException {
		Map<String,Object> resultMap = new HashMap<>();
		//新增票数据
		int i = appealDao.addAppeal(paramsMap);
		if(i <= 0){
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg ", "新增失败");
		}else{
			resultMap.put("returnCode", 1);
			resultMap.put("returnMsg", "新增成功");
			}
	    return resultMap;
	}

	@Override
	public Map<String, Object> queryAppealPage(Map<String, Object> paramsMap)
			throws DataAccessException {
		Map<String,Object> resultMap = new HashMap<>();
		int pagenum = Integer.parseInt(paramsMap.get("pagenum").toString());
		int pagesize = Integer.parseInt(paramsMap.get("pagesize").toString());
		paramsMap.put("pagestart", (pagenum-1) * pagesize);
		List<Map<String,Object>> appealList = appealDao.queryAppealPage(paramsMap);
		int counts = appealDao.queryAppealCounts(paramsMap);
		if(appealList != null && appealList.size() > 0){
			resultMap.put("returnCode", 1);
			resultMap.put("ListData",appealList);
			resultMap.put("TotalCount",counts);
			resultMap.put("TotalPage",counts % pagesize >0 ? counts/pagesize + 1 : counts/pagesize);
			resultMap.put("returnMsg", "操作成功");
		}else{
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "系统无数据");
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> queryAppealById(Map<String, Object> paramsMap)
			throws DataAccessException {
		Map<String,Object> resultMap = new HashMap<>();
		Map<String,Object> appealInfo = appealDao.queryAppealById(paramsMap);
		if(appealInfo != null){
			resultMap.put("returnCode", 1);
			resultMap.put("ListData", appealInfo);
			resultMap.put("returnMsg", "操作成功");
		}else{
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "系统查询不到该条信息");
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> updateAppeal(Map<String, Object> paramsMap)
			throws DataAccessException {
		Map<String,Object> resultMap = new HashMap<>();
		int i = appealDao.updateAppeal(paramsMap);
		if(i <= 0){
			resultMap.put("returnCode", 0);
			resultMap.put("returnMsg", "更新失败");
		}else{
			resultMap.put("returnCode", 1);
			resultMap.put("returnMsg", "更新成功");
		}
		return resultMap;
	}

}
